package ch.fusun.baron.map.configuration;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

import ch.fusun.baron.core.injection.Inject;
import ch.fusun.baron.map.api.GameMapService;
import ch.fusun.baron.map.configuration.messages.Messages;
import ch.fusun.baron.serverapp.configuration.ConfigurationPart;

/**
 * Configures the map
 */
public class MapConfigurationPart implements ConfigurationPart {

	private Text widthText;
	private Text heightText;
	@Inject
	private GameMapService mapService;

	/**
	 * Constructor
	 * 
	 */
	public MapConfigurationPart() {
	}

	@Override
	public void createPartControl(Composite area) {
		Label widthLabel = new Label(area, SWT.NONE);
		widthLabel.setText(Messages.MapConfigurationPart_Width);
		widthText = new Text(area, SWT.BORDER);
		Label heightLabel = new Label(area, SWT.NONE);
		heightLabel.setText(Messages.MapConfigurationPart_Height);
		heightText = new Text(area, SWT.BORDER);
		Button button = new Button(area, SWT.PUSH);
		button.setText(Messages.MapConfigurationPart_Configure);
		button.addSelectionListener(new SelectionAdapter() {

			@Override
			public void widgetSelected(SelectionEvent e) {
				mapService.configure(Integer.parseInt(widthText.getText()),
						Integer.parseInt(heightText.getText()));
			}

		});
	}
}
